"""处理时间格式"""
def sanitize(time_string):
    if "-" in time_string:
        spliter = "-"
    elif ":" in time_string:
        spliter = ":"
    else:
        return time_string
    (mins, secs) = time_string.split(spliter)
    return mins + '.' + secs


"""读取文件数据"""
def get_file_data(filename):
    try:
        with open(filename) as files:
            data = files.readline()
            temp_list = data.strip().split(",")
            return Athlete(temp_list.pop(0),
                           temp_list.pop(0),
                           temp_list)
    except IOError as err:
        print("File Error" + err)


"""实体类"""
class Athlete:
    def __init__(self, name, dob=None, times=[]):
        self.name = name
        self.dob = dob
        self.times = times
        pass

    def top3(self):
        return sorted(set([sanitize(t) for t in self.times]), reverse=True)[0:3]

    def print_data(self):
        print(self.name + " fast times is :" + str(self.top3()))

    def add_time(self, time_value):
        self.times.append(time_value)

    def add_times(self, time_list):
        self.times.extend(time_list)


"""执行"""
james = get_file_data("F:/data/file7/james.txt")
sarah = get_file_data("F:/data/file7/sarah.txt")
julie = get_file_data("F:/data/file7/julie.txt")
mikey = get_file_data("F:/data/file7/mikey.txt")

james.add_time('4.21')
sarah.add_times(['3.52', '3.55'])
james.print_data()
sarah.print_data()
julie.print_data()
mikey.print_data()
